package com.ovo.dailypayaccount.controller;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.ovo.dailypayaccount.entity.UserInfo;
import com.ovo.dailypayaccount.service.BaseUserService;

@Controller
public class PageSkipHandleController {
	@Autowired
	private BaseUserService userService;
	/**
	 * 页面跳转
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/skipToPage")
	public ModelAndView skipToChgpwdPage(HttpServletRequest request, HttpServletResponse response) {
		String thePage = request.getParameter("thePage");//新密码
		ModelAndView result = new ModelAndView(thePage);
		Cookie[]cookies = request.getCookies();
		UserInfo user = null;
		String userId = null;
		if(cookies!=null) {	
			for(Cookie cookie:cookies) {
				if(cookie.getName().equals("userId")) {
					userId = cookie.getValue();
				}
			}
			if(userId!=null) {
				user = userService.getUserById(Integer.valueOf(userId));
				if(user!=null) {
					result.addObject("userName", user.getName());
				}else {
					result.addObject("userName", "游客");
				}
			}
			}
		return result;
	}


}
